﻿using System;
using System.Diagnostics.Contracts;

namespace Isuka.Iteration
{
    public static class IteratorExtensions
    {

        public static TIterator Next<TIterator>(this TIterator it)
            where TIterator : class, IIterator, ICloneable
        {
            Contract.Requires<ArgumentNullException>(it != null, "it");
            Contract.Ensures(Contract.Result<TIterator>() != null);

            var wrk = Utility.Copy(it);
            wrk.MoveNext();
            return wrk;
        }

        public static TIterator Prior<TIterator>(this TIterator it)
            where TIterator : class, IBidirectionalIterator
        {
            Contract.Requires<ArgumentNullException>(it != null, "it");
            Contract.Ensures(Contract.Result<TIterator>() != null);

            var wrk = Utility.Copy(it);
            wrk.MovePrev();
            return wrk;
        }
    }
}
